<template>
  <div>
    <RouteTitle isBack />
    <a-spin tip="加载中..." :spinning="spinning">
      <div class="card-content bg">
        <a-descriptions title="基础信息">
          <a-descriptions-item v-for="(item, index) in clipDetailObj?.basic" :label="item.title">{{ item.value
            }}</a-descriptions-item>
        </a-descriptions>
        <a-divider />

        <a-descriptions title="全局信息">
          <a-descriptions-item v-for="(item, index) in gloData" :label="item.title">{{ item.value
            }}</a-descriptions-item>
        </a-descriptions>
        <a-divider />

        <!-- 镜头组信息 -->
        <div>
          <h3>镜头组信息</h3>
          <div class="card_D" v-for="(item, index) in videoData" :key="index">
            <div class="card-top">
              <span>镜头组名称: </span> <span>{{ item.name }}</span>
            </div>

            <div class="card-content_D">
              <div class="card-content_D-left">
                <div class="card_D_right_one">
                  <div class="left">字幕与配音:</div>
                  <a-tooltip placement="top">
                    <template #title>
                      <span>{{ item.tts_config[0].subtitle[0].text }}</span>
                    </template>
                    <div class="text">
                      {{ item.tts_config[0].subtitle[0].text }}
                    </div>
                  </a-tooltip>
                </div>
                <div class="card_D_right_one">
                  <div class="left">文字标题:</div>

                  <a-tooltip placement="bottom">
                    <template #title>
                      <span>{{ item.text_config[0].text }}</span>
                    </template>
                    <div class="text">{{ item.text_config[0].text }}</div>
                  </a-tooltip>
                </div>
                <div class="card_D_right_one" style="display: flex">
                  <div class="two_yang">
                    <span class="left">时长设置: </span>
                    <span class="Three_left">
                      <template v-if="item.time_strategy.type === 0">视频原始时长</template>
                      <template v-if="item.time_strategy.type === 1">随音频，视频自动变速</template>
                      <template v-if="item.time_strategy.type === 2">随音频，视频智能截取</template>
                      <template v-if="item.time_strategy.type === 3">固定时长，智能去重</template>
                    </span>
                  </div>

                  <!-- <div class="two_yang">
										<span class="left">智能混剪: </span>
										<span>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</span>
									</div> -->
                </div>
              </div>

              <div class="card-content_D-right">
                <div class="card-conten_D_right_top">
                  素材({{ item.material_list.length }})
                </div>
                <div class="card-conten_D_right_bottom">
                  <div v-for="(v1, index1) in item.material_list.slice(0, 7)" :key="index1" class="material_list_item">
                    <video style="
                        width: 120px;
                        height: 150px;
                        background-color: #000;
                      " :src="v1.material_url" v-if="v1.scene_type == 'video'"></video>
                    <img :src="v1.material_url" style="
                        width: 120px;
                        height: 150px;
                        background-color: #000;
                      " alt="" v-if="v1.scene_type == 'image'" />
                  </div>

                  <a-popover>
                    <template #content>
                      <div style="
                          max-width: 500px;
                          max-height: 240px;
                          overflow: auto;
                          display: flex;
                        ">
                        <div v-for="(v1, index1) in item.material_list.slice(7)" :key="index1" class="pop_img">
                          <video style="
                              width: 120px;
                              height: 150px;
                              background-color: #000;
                            " :src="v1.material_url"></video>
                        </div>
                      </div>
                    </template>
                    <span v-if="item.material_list.length > 7" class="more_num">+{{ item.material_list.length - 7
                      }}</span>
                  </a-popover>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </a-spin>
    <!-- 字幕效果 -->
    <SubtitleSettings :visible="visibleSubtitle" @close="visibleSubtitle = false" />

    <!-- 预览弹框 -->
    <PreviewModal :visible="visiblePreview" :title="fileData.name" :url="fileData.url" :type="fileData.type"
      @onCancel="visiblePreview = false" />
  </div>
</template>

<script>
import { reactive, toRefs, defineComponent, onMounted } from "vue";
import SubtitleSettings from "../EditingCenter/modules/bottomSet/modules/subtitleSettings.vue";
import PreviewModal from "../../../components/PreviewModal/index.vue";
import { useRoute, useRouter } from "vue-router";
import request from "../../../common/utils/request";
import musicCom from "./components/musicCom.vue";
import broadCom from "./components/broadCom.vue";
import wordCom from "./components/wordCom.vue";
import stickerCom from "./components/stickerCom.vue";
import coverCom from "./components/coverCom.vue";
import templateWord from "./components/templateWord.vue";
export default defineComponent({
  name: "ClipDetail",
  components: {
    SubtitleSettings,
    PreviewModal,
    musicCom,
    broadCom,
    wordCom,
    stickerCom,
    coverCom,
    templateWord,
  },
  setup() {
    const router = useRouter();
    const route = useRoute();

    const state = reactive({
      count: 0,
      modelName: "",
      clipDetailObj: {},
      visibleSubtitle: false,
      visiblePreview: false,
      fileData: {},
      activeKey: "music",
      radioType: "9:16",
      templateInfo: {},
      videoList: [],
      activeList: [
        {
          title: "音乐",
          num: 0,
          key: "music",
        },
        {
          title: "口播",
          num: 0,
          key: "broad",
        },
        {
          title: "文字",
          num: 0,
          key: "word",
        },
        {
          title: "贴纸",
          num: 0,
          key: "sticker",
        },
        {
          title: "封面",
          num: 0,
          key: "cover",
        },
      ],
      videoData: [],
      gloData: [],
      spinning: false,
    });

    const viewSubtitle = () => {
      state.visibleSubtitle = true;
    };

    const previewClick = (item) => {
      state.fileData.type = item.material_type;
      state.fileData.name = item.material_name;
      state.fileData.url = item.material_url;
      state.visiblePreview = true;
    };

    const getClipDetail = () => {
      state.spinning = true;
      request
        .get("/work_ai", "/user/shotstack/look/record/detail", {
          id: Number(route.query.id),
        })
        .then((res) => {
          state.spinning = false;
          state.clipDetailObj = res.result;
          state.videoData = res.result.resource_data;

          res.result.basic.forEach((item) => {
            if (item.title === "全局字幕配音") {
              state.gloData.push(item);
            } else if (item.title === "全局文字标题") {
              state.gloData.push(item);
            } else if (item.title === "全局文字标题") {
              state.gloData.push(item);
            } else if (item.title === "背景音乐") {
              state.gloData.push(item);
            } else if (item.title === "转场设置") {
              state.gloData.push(item);
            } else if (item.title === "滤镜设置") {
              state.gloData.push(item);
            } else if (item.title === "背景设置") {
              state.gloData.push(item);
            } else if (item.title === "视频封面") {
              state.gloData.push(item);
            } else if (item.title === "模版比例") {
              state.gloData.push(item);
            } else if (item.title === "视频分辨率") {
              state.gloData.push(item);
            }
          });

          state.clipDetailObj.basic.splice(3, 9);
          state.clipDetailObj.basic.splice(3);

          // debugger
          console.log(state.clipDetailObj.basic, "2222222222222222222");
        })
        .catch(() => {
          state.spinning = false;
        });
    };

    onMounted(() => {
      getClipDetail();
    });

    return {
      ...toRefs(state),
      viewSubtitle,
      previewClick,
    };
  },
});
</script>

<style lang="less" scoped>
:deep(.ss-descriptions-row > td) {
  padding-bottom: 5px !important;
}

.bg {
  background: rgba(255, 255, 255, 0.4);
}

.sence_con {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-direction: column;
  width: 100%;
  margin-top: 10px;

  .top_container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;

    .sence_title {
      display: flex;
      align-items: center;
      justify-content: flex-start;
      width: 50%;

      .title_item {
        display: flex;
        align-items: center;
        margin-left: 15px;

        &:nth-child(1) {
          margin-left: 0px;
        }
      }
    }

    .right_special {
      width: 50%;
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
  }

  .bottom_container {
    width: 100%;
    margin-top: 10px;
  }
}

.video_list {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  transform: translateX(-10px) translateY(-30px);

  .video_item {
    width: 83px;
    height: 83px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(0, 0, 0, 0.9);
    position: relative;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 30px;
    margin-left: 10px;

    video {
      max-width: 80px;
      max-height: 80px;
    }

    img {
      max-width: 80px;
      max-height: 80px;
    }

    .video_name {
      position: absolute;
      width: 80px;
      font-size: 12px;
      color: #333;
      left: 0;
      bottom: -24px;
      display: inline-block;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      text-align: center;
    }
  }
}

.card-content {
  width: 100%;
  padding: 20px;
  margin: 20px 0;
  border: 1px solid #f0efef;
  border-radius: 10px;

  .content {
    width: 100%;
  }
}

.image_text_content {
  width: 100%;
  display: flex;

  .left_model {
    width: 150px;
    min-height: 150px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;

    .top_image {
      img {
        max-height: 100px;
        max-width: 100px;
      }
    }

    .bottom_text {}

    border-right: 1px solid #eee;
  }

  .right_image {
    width: calc(50% - 90px);
    min-height: 150px;
    margin-left: 20px;
    border-right: 1px solid #eee;

    .image_title {
      height: 30px;
    }

    .text_list {
      display: flex;
      transform: translateX(-10px) translateY(-10px);
      flex-direction: column;
      flex-wrap: wrap;
      width: 100%;

      .text_item {
        width: 100%;
        margin-left: 10px;
        margin-top: 10px;
        background-color: #fafafa;
        padding: 5px 10px;

        .ellipse_text {
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
          display: inline-block;
        }
      }
    }

    .image_list {
      display: flex;
      align-items: center;
      transform: translateX(-10px);
      flex-wrap: wrap;

      img {
        max-height: 90px;
        max-width: 90px;
        margin-left: 10px;
        cursor: pointer;
      }
    }
  }
}

.card_D {
  width: 100%;
  height: 300px;
  border-radius: 10px;
  background-color: #fff;
  margin-bottom: 20px;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.06);
  transition: box-shadow 0.3s ease;

  .card-top {
    font-size: 16px;
    padding: 20px;
    border-bottom: 1px solid #f0efef;
  }

  .card-content_D {
    padding: 20px;
    width: 100%;
    height: 200px;
    display: flex;

    .card-content_D-left {
      width: 30%;
      font-size: 14px;
      margin-top: 23px;
      padding-right: 20px;

      .card_D_right_one {
        height: 40px;
        width: 100%;
        overflow: hidden;
        margin-bottom: 10px;
        display: flex;
        align-items: center;

        .text {
          display: block;
          width: 80%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .left {
          font-size: 14px;
          margin-right: 10px;
        }

        .Three_left {
          margin-right: 20px;
        }

        .two_yang {
          width: 50%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }

    .card-content_D-right {
      width: 70%;
      // background-color: palevioletred;
      padding-left: 20px;
      border-left: 1px solid #f0efef;

      .card-conten_D_right_top {
        font-size: 14px;
        margin-bottom: 10px;
      }

      .card-conten_D_right_bottom {
        display: flex;
        overflow: hidden;
        position: relative;

        .card-conten_D_bottom_img {
          width: 144px;
          height: auto;
          object-fit: contain;
          margin-right: 10px;
        }
      }
    }
  }
}

.card_D:hover {
  box-shadow: 0 8px 12px rgba(0, 0, 0, 0.2), 0 3px 6px rgba(0, 0, 0, 0.1);
}

.material_list_item {
  margin-right: 20px;
}

.more_num {
  font-size: 20px;
  color: #fff;
  position: absolute;
  top: 66px;
  right: 166px;
  cursor: pointer;
}

.pop_img {
  display: flex;
  margin-right: 20px;
  margin-bottom: 20px;
}
</style>
